﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoShopping.Model;

namespace GoShopping.BLL.SysInfo
{
    public class DicTagBean
    {
        /// <summary>
        /// 获取所有标签字典数据
        /// </summary>
        /// <returns></returns>
        public IList<DicTag> GetAllTag()
        {
            return Databases.DBGoShopping.Select(GoShoppingNBear.DicTag).ToList<DicTag>();
        }

        /// <summary>
        /// 添加一个标签
        /// </summary>
        /// <param name="Tag"></param>
        /// <returns></returns>
        public bool AddDicTag(string Tag)
        {
            int i = Databases.DBGoShopping.Select(GoShoppingNBear.DicTag, GoShoppingNBear.DicTag.ID.Count()).Where(
                GoShoppingNBear.DicTag.Name == Tag).ToScalar<int>();
            if (i > 0)
            {
                return false;
            }
            i = Databases.DBGoShopping.Insert(
                GoShoppingNBear.DicTag).AddColumn(
                GoShoppingNBear.DicTag.Name, Tag).Execute();
            if (i > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一个标签
        /// </summary>
        /// <param name="dicTagID"></param>
        /// <returns></returns>
        public bool DelDicTag(int dicTagID)
        {
            int i = Databases.DBGoShopping.Delete(GoShoppingNBear.DicTag).Where(
                GoShoppingNBear.DicTag.ID == dicTagID).Execute();
            if (i > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一个标签
        /// </summary>
        /// <param name="TagName"></param>
        /// <returns></returns>
        public bool DelDicTagByName(string TagName)
        {
            int i = Databases.DBGoShopping.Delete(GoShoppingNBear.DicTag).Where(
               GoShoppingNBear.DicTag.Name == TagName).Execute();
            if (i > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
